#Download

import wx
try:
	import psyco
except:
	pass
import sys
sys.path.append("/usr/share/asylum")
import math, time, os, urllib2, datetime, subprocess
from Ui import Ui

class Download:
    def __init__(self, parent):
        self.parent = parent
        self.queue = parent.queue
        self.profile = parent.profile
        self.showSplash()
        self.getProfile()
        self.download()

    def logMessage(self, msg):
        self.queue.put(msg)
        wx.WakeUpIdle()

    def showSplash(self):
        self.logMessage('STATUS|Downloading...')
        splash = """
Asylum Build System V0.1 Alpha (DO NOT RUN)
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
	by:
		Ian (Inc)
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
"""
        self.logMessage(splash)

    def getProfile(self):
        sUrltemplate = self.parent.sUrltemplate
        sFiletemplate = self.parent.sFiletemplate
        self.sFile = datetime.date.today().strftime(sFiletemplate)
        self.sUrl = sUrltemplate + self.sFile
        source = "The source that is being grabbed is: "
        self.logMessage(source + self.sUrl + '\n')

    def download(self):
        ui = Ui(self)
        ui.download([self.sUrl], self.sFile)
        done = " has finished downloading now moving onto: "
        dstep = "\nDependency download"
        self.logMessage(self.sFile + done + dstep + '\n')
        self.logMessage('\nThis is as far as it goes for now... cw\n')







